
package com.probiz.estore.webapp.util;

import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class ResponseContext {
	private static ThreadLocal<HttpServletResponse>	currentHttpResponseHolder = new ThreadLocal<HttpServletResponse>();

	private static final Log logger = LogFactory.getLog(ResponseContext.class);

	public static void clearCurrentHttpResponse() {
		currentHttpResponseHolder.set(null);
	}

	public static HttpServletResponse getCurrentHttpResponse() {
		return currentHttpResponseHolder.get();
	}

	/**
	 * 过滤每次请求时设置当前的请求到此类中，参见{@link com.probiz.estore.webapp.filter.ActionFilter#doFilterInternal}
	 * 
	 * @param Response
	 */
	public static void setCurrentHttpResponse(HttpServletResponse response) {
		if (currentHttpResponseHolder.get() != null) {
			logger.error("Duplicate call to setCurrentHttpResponse");
		} else {
			currentHttpResponseHolder.set(response);
		}
	}

}
